package model

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var mysqlDb *gorm.DB

func init() {
	// init db
	GetDb()
	// automigrate
	mysqlDb.AutoMigrate(&ChatLog{})
	mysqlDb.AutoMigrate(&SendChat{})
	mysqlDb.AutoMigrate(&User{})
	mysqlDb.AutoMigrate(&AccountLog{})
}

func GetDb() (db *gorm.DB) {
	var err error
	dsn := "root:yexk!@123@tcp(127.0.0.1:13306)/qqbot?charset=utf8mb4&parseTime=True&loc=Local"
	db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("init mysql connect faild")
	}
	mysqlDb = db
	return
}
